/-boot
/-docs
/-editor
CodeMirrorEditor.ts
CompletionCodeMirrorEditor.ts
CssEditorType.ts
Editor.ts
EditorType.ts
HtmlEditorType.ts
JavaScriptEditorType.ts
TypeScriptEditorType.ts
x-last-PlainTextEditorType.ts
/-files
/-files-old
/-imports
/-layout
/-shell
/-storage
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
x
 
1
module teapo {
2
​
3
  /**
4
   * Hadles high-level application behavior,
5
   * creates and holds DocumentStorage and FileList,
6
   * that in turn manage persistence and file list/tree.
7
   *
8
   * Note that ApplicationShell serves as a top-level
9
   * ViewModel used in Knockout.js bindings.
10
   */
11
  export class ApplicationShell {
12
​
13
    saveDelay = 1500;
14
    fileList: FileList = null;
15
​
16
    toolbarExpanded = ko.observable(false);
17
    statusText = ko.observable('ready.');
18
​
19
    private _selectedDocState: DocumentState = null;
20
    private _editorElement: HTMLElement = null;
21
    private _editorHost: HTMLElement = null;
22
    private _saveTimeout = 0;
23
    private _saveSelectedFileClosure = () => this._invokeSaveSelectedFile();
24
​
25
    savingFiles: ko.ObservableArray<string>;
26
​
27
    constructor(private _storage: DocumentStorage) {
28
    
29
      if (this._storage.editedUTC){
30
        var dt = new Date(this._storage.editedUTC);
31
        this.statusText('Updated ' + dt.getFullYear() + '-' + dt.getMonth() + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes()+'.');
32
      }
33
​
34
      this.savingFiles = this._storage.savingFiles;
35
    
36
      this.fileList = new FileList(this._storage);
37
  
38
      this.fileList.selectedFile.subscribe((fileEntry) => this._fileSelected(fileEntry));
39
​
40
      // loading editors for all the files
41
      var allFilenames = this._storage.documentNames();
42
      allFilenames.sort();
43
      for (var i = 0; i < allFilenames.length; i++) {
44
        var docState = this._storage.getDocument(allFilenames[i]);
45
        docState.editor();
46
      }
47
    }
48
​
49
    keyDown(self, e: KeyboardEvent) {
50
      switch (e.keyCode) {
51
        case 78:
52
          if ((<any>e).cmdKey || e.ctrlKey || e.altKey) {
53
            this.newFileClick();
54
​
55
            if (e.preventDefault)
56
              e.preventDefault();
57
            if ('cancelBubble' in e)
58
              e.cancelBubble = true;
59
            return false;
60
          }
61
          break;          
62
      }
0:0